<template>
	<view class="content">
		<!-- pos地址 -->
		<view class="address">
			<view class="address_detail">
				<view class="address_right" >
					<view class="nickname_phone">
						<view class="nickname">{{ address.name }}</view>
						<view class="phone">{{ address.mobile }}</view>
					</view>
					
					<view class="address_con">
						<view class="address_i">
							<image src="https://jialianxin-1301053941.cos.ap-chengdu.myqcloud.com/static/adds.png" mode="aspectFit"></image>
						</view>
						<view class="address_s" v-if="type=='store' && address.Area">
							{{ address.Area.province + address.Area.city + address.Area.region + address.detail ? address.Area.province + address.Area.city + address.Area.region + address.detail : '用户未填写地址' }}
						</view>
						<view class="address_s" v-else>
							{{ address.province + address.city + address.area + address.details ? address.province + address.city + address.area + address.details : '用户未填写地址' }}
						</view>
					</view>
				</view>
			</view>
		</view>
		
		
		<!-- pos机商品 -->

         <view class="order_wrap" >
			<view class="order_item" >
				<view class="order_top">
					<view class="top_left"><image :src="Config_ysy.image_url + posgoods.image"></image></view>
					<view class="top_right">
						<view class="tops">
							<view class="goods_name">{{ posgoods.name }}</view>
							<view class="yunfei">￥{{posgoods.price}}</view>
						</view>
						<view style="font-size: .5em; color: gray; margin-top: 1em;">数量 x1</view>
						<view style="font-size: .5em; color: gray;">已付：{{posgoods.price}}</view>
						<view style="font-size: .5em; color: gray;">现场发货:预计3分钟</view>
						<view style="font-size: .5em; color: gray;">总部发货:预计3到5天</view>
					</view>
				</view>
			</view>
		</view>
		
		 <view class="order_wrap" style="margin-bottom:15rpx;" >
			
			<view class="choose_transfer_box" v-if="currentTab == 0">
				<view class="choose_transfer">
					<view class="choose_transfer_wrap">
						<view class="sreening_wrap" style="margin-bottom: 10rpx; text-align: center;">
							<text :class="activeIndex==index?'textActive':''" style="display: inline-block; border:1rpx solid rgba(34, 36, 38, 0.15); padding:5rpx 10rpx; margin-right: 10rpx; border-radius:25rpx;" v-for="(item, index) in type_obj" :key="index" @click="select_load(item,index)">{{ item.name }}</text>
						</view>
					</view>
				</view>
				<view class="card_list_wrap" style="text-align: center;" >
					<radio-group @change="changeCheckbox">
						<!-- <empty v-if="loaded === true && checkboxData.length === 0"></empty> -->
						<label class="card_item" v-for="(item, index) in checkboxData" :key="index">
							<view class="card_list" style="padding: 10rpx 0; border-bottom:solid 1rpx rgba(34, 36, 38, 0.15);">
								<text style="font-size: 1.2em;display: inline-block; width: 80%; text-align: center;">{{ item.sn }}</text>
								<radio :value="item.id.toString()" style="transform: translateY(-5rpx);" :checked="item.id === current" />
							</view>
						</label>
						<uni-load-more :status="loadingType"></uni-load-more>
					</radio-group>
				</view>
			</view>
			
		 </view>

		<!-- 底部栏 -->
		<view class="bottom_bar">
			<view class="bar_left"></view>
			<!-- 防止报错（undefind） -->
			<view class="bar_right" >
				<text style="position: fixed;left:30rpx;font-size:.5em; color:gray;" >共1件</text>
				<view class="jiesuan"><view class="jiesuan_btn" @click="toOrder">总部划拨</view></view>
				<view class="jiesuan"><view class="jiesuan_btn" @click="toTransferPeople">现场划拨</view></view>
			</view>
		</view>
		
	</view>
</template>

<script>
import openAlert from '../../components/open-alert/open-alert.vue';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
export default {
	components: { openAlert, uniLoadMore, empty },
	data() {
		return {
			activeIndex:3,
			address: {
				"name":"测试",
				"mobile":"123456789",
			},
			posgoods:{},
			ids: [],
			orderId : 0,
			orderKey:0,
			total: 0,
			startend: '',
			endcode: '',
			remark: '',
			trnum: '',
			num: 0,
			checkedArr: [], //复选框选中的值
			allChecked: false, //是否全选
			AlertClass: 0,
			AlertPosition: '',
			currentTab: 0,
			top_tab: [
				{
					tab_name: '选择划拨'
				},
				{
					tab_name: '区间划拨'
				}
			],

			loaded: false,
			loadingType: 'more',
			pageNum: 1,
			limit: 10,
			type_id: 0,
			type_obj: [],
			current:0,
			token:'',
			checkboxData: [
				// {
				// 	card_name:'洁牙卡1-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡3-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡3-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡4-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡5-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡6-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡7-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡8-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡9-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡10-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡11-卡号',
				// 	card_num:'013404'
				// },{
				// 	card_name:'洁牙卡12-卡号',
				// 	card_num:'013404'
				// }
			]
		};
	},
	onLoad(opt) {
		this.orderId = opt.oid
		this.orderKey = opt.key
		this.token=opt.token
		//console.log(opt)
	},
	onShow() {
		//显示内容
		this.loadData(0);
		this.loadAddress();
		
		//获取类型列表
		let params = {
			page: this.pageNum,
			limit: this.limit,
			category_id: this.type_id,
			token:this.token
		};
		// GET/api/usercenter/device/category
		var url = '/api/usercenter/device/category';
		this.Unfold_data.upload_data(params, 'GET', url, res => {
			if (res.statusCode == 200 && res.data.code == 1) {
				this.type_obj = res.data.data;
			} else {
				this.Unfold_data.showWindow(res.data.msg);
			}
		});
	},
	onReachBottom() {
		this.loadData(1);
	},
	methods: {
		//选择pos机类型
		select_load(item,index) {
			this.activeIndex = index;
			this.type_id = item.id;
			this.pageNum = 1
			this.loadData(3);
		},
		
		// 获取订单地址跟信息
		loadAddress(){
			var url = '/api/cshop/posorder/details';
			this.Unfold_data.upload_data({id:this.orderId,token:this.token}, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
					 this.address = res.data.data.addres;
					 this.posgoods = res.data.data.posgoods;
				}
			})
		},
		
		//分页获取好啵设备
		loadData(source) {
			//source 防止重复加载
			if (source == 0 && this.loaded) {
				return;
			}
			if (source == 1 && this.loadingType != 'more') {
				return;
			}
			if (source == 3) {
				this.checkboxData = [];
			}

			let params = {};
			if (this.type_id == 0) {
				params = {
					page: this.pageNum,
					limit: this.limit,
					token:this.token
				};
			} else {
				params = {
					page: this.pageNum,
					limit: this.limit,
					category_id: this.type_id,
					token:this.token
				};
			}
			var url = '/api/usercenter/device';
			this.Unfold_data.upload_data(params, 'GET', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
					//赋值
					this.endcode = res.data.data.sn;
					this.total = res.data.data.total;
					if (source == 0) {
						this.loaded = true;
					}
					if (!res.data.data.rows) {
						this.loadingType = 'noMore';
					} else if (res.data.data.rows.length < this.limit) {
						this.loadingType = 'noMore';
						if (res.data.data.rows.length > 0) {
							this.checkboxData = this.checkboxData.concat(res.data.data.rows);
						}
					} else if (res.data.data.rows.length == this.limit) {
						if (res.data.data.rows.length > 0) {
							this.checkboxData = this.checkboxData.concat(res.data.data.rows);
						}
						this.pageNum = this.pageNum + 1;
					}
					this.$refs.openAlert.Close();
				} else if (res.statusCode == 200 && res.data.code == 401) {
					this.Unfold_data.showWindow(res.data.msg);
				} else {
					this.Unfold_data.showWindow(res.data.msg);
				}
			});
		},
		startends(e) {
			// console.log(e);
			this.startend = e.detail.value;
		},
		//监听划拨
		trnume(a) {
			// console.log();
			let params = {
				// T文本	是
				sn: this.startend,
				//起始编号
				num: Number(a.detail.value),
				token:this.token
			};
			var url = '/api/usercenter/device/endSn';
			this.Unfold_data.upload_data(params, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
					//获取截至编号
					this.endcode = res.data.data.sn;
				} else if (res.statusCode == 200 && res.data.code == 401) {
					this.Unfold_data.showWindow(res.data.msg);
				} else {
					this.Unfold_data.showWindow(res.data.msg);
				}
			});
		},
		changeTab(index) {
			this.currentTab = index;
		},
		// 多选复选框改变事件
		changeCheckbox(e) {
			this.current = e.detail.value;
		},
		submitForm(e) {
			//区间划拨
			if (!e.detail.value.startend) {
				this.Unfold_data.showWindow('起始序列号不能为空');
				return;
			}
			if (!e.detail.value.trnume) {
				this.Unfold_data.showWindow('划拨数量不能为空');
				return;
			}

			let params = {
				//开始
				sn: this.startend,
				//结束
				end: this.endcode,
				//划拨数量
				num: e.detail.value.trnume
			};
			uni.setStorageSync('par', params);
			uni.navigateTo({
				url: '/pages/transferPeople/transferPeople?token='+this.token
			});
		},
		toTransferRecord() {
			uni.navigateTo({
				url: '/pages/transferRecord/transferRecord?token='+this.token
			});
		},
		toTransferPeople() {
			if (this.current=='') {
				this.Unfold_data.showWindow('请选择设备');
				return;
			}
			let orderKey = this.orderKey;
			var url = '/api/cshop/posorder/deliver';
			this.Unfold_data.upload_data({
				"oid":this.orderId,
				"cid":this.current,
				 token:this.token
			}, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
				     this.Unfold_data.showWindow(res.data.msg);
					 setTimeout(function () {
						  uni.setStorageSync('delete_array',orderKey);
						  uni.navigateBack({delta: 1});
					 }, 2000);
				}
			})
		},
		toOrder(){
			let orderKey = this.orderKey;
			let params = {"oid":this.orderId,token:this.token}
			let url = "/api/cshop/posorder/totalOder";
			this.Unfold_data.upload_data(params, 'POST', url, res => {
				if (res.statusCode == 200 && res.data.code == 1) {
				     this.Unfold_data.showWindow(res.data.msg);
					 setTimeout(function () {
						  uni.setStorageSync('delete_array',orderKey);
						  uni.navigateBack({delta: 1});
					 }, 2000);
				}else{
					this.Unfold_data.showWindow(res.data.msg);
				}
			})
		},
		//打开弹出层
		open(Class, Position) {
			this.$nextTick(function() {
				this.AlertClass = Class;
				this.AlertPosition = Position;
				this.$nextTick(function() {
					this.$refs.openAlert.Show();
				});
			});
		}
	}
};
</script>

<style lang="scss">
page {
	width: 100%;
	height: 100%;
	background: #ededed;
}
.content {
	width: 100%;
	padding-bottom: 100upx;
	position: relative;
	.address {
		width: 90%;
		margin: 0 auto;
		margin-top: 40upx;
		margin-bottom: 50upx;
		background: #ffffff;
		border-radius: 20upx;
		display: flex;
		align-items: center;
		justify-content: center;
		.address_no{
			width: 90%;
			margin: 0 auto;
			.address_title{
				width: 100%;
				height: 60upx;
				border-bottom: 3upx solid #ededed;
				display: flex;
				align-items: center;
				font-size: 28upx;
			}
			.addAddress {
				width: 100%;
				display: flex;
				align-items: center;
				padding: 20upx 0;
				.add_img {
					flex: 1;
					image {
						width: 60upx;
						height: 60upx;
					}
				}
				.add_name {
					flex: 6;
					color: #7c7c7c;
				}
			}
		}
		.address_detail {
			width: 90%;
			margin: 0 auto;
			display: flex;
			align-items: center;
			.address_left {
				flex: 2;
				image {
					width: 102upx;
					height: 102upx;
				}
			}
			.address_right {
				// flex: 8;
				width: 100%;
				.change_address {
					width: 100%;
					height: 60upx;
					font-size: 20upx;
					color: #9f9f9f;
					display: flex;
					align-items: center;
					justify-content: flex-end;
					border-bottom: 3upx solid #ededed;
					text{
						padding-right: 10upx;
					}
					.address_img{
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 25upx;
							height: 25upx;
						}
					}
				}
				.nickname_phone {
					width: 100%;
					height: 80upx;
					display: flex;
					align-items: center;
					.nickname {
						flex: 1;
					}
					.phone {
						flex: 3;
						color: #7c7c7c;
					}
					.address_img{
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 25upx;
							height: 25upx;
						}
					}
				}
				.address_con {
					width: 100%;
					display: flex;
					align-items: center;
					padding-bottom: 30upx;
					.address_i{
						padding-right: 15upx;
						display: flex;
						align-items: center;
						justify-content: center;
						image{
							width: 30upx;
							height: 30upx;
						}
					}
					.address_s{
						font-size: 24upx;
						display: -webkit-box;
						overflow: hidden;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
					}
				}
			}
		}
	}
	.order_wrap {
		width: 90%;
		margin: 0 auto;
		padding: 20upx;
		background: #ffffff;
		border-radius: 20upx;
		margin-top: 15upx;
		display: flex;
		align-items: center;
		justify-content: center;
		.order_item {
			width: 95%;
			margin: 0 auto;
			display: flex;
			flex-direction: column;
			justify-content: center;
			.order_top {
				flex: 8;
				width: 100%;
				display: flex;
				justify-content: center;
				.top_left {
					flex: 3;
					image {
						border-radius: 10upx;
						width: 200upx;
						height: 200upx;
					}
				}
				.top_right {
					flex: 7;
					padding-left: 30upx;
					.tops{
						width: 100%;
						display: flex;
						// align-items: center;
						.goods_name {
							flex: 1;
							font-weight: bold;
							display: -webkit-box;
							overflow: hidden;
							-webkit-box-orient:vertical;
							-webkit-line-clamp:1;
						}
						.yunfei {
							flex: 1;
							text-align: right;
							color: #d74646;
							font-size: 34upx;
						}
					}
					
					.order_bottom {
						margin-top: 50upx;
						font-size: 26upx;
						padding: 10upx 0;
						color: #7c7c7c;
					}
					.goods_bottom {
						padding-top: 10upx;
						.fahuo_time {
							font-size: 26upx;
							color: #7c7c7c;
						}
					}
				}
			}
		}
	}
	.bottom_bar {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 100upx;
		display: flex;
		align-items: center;
		background: #FFFFFF;
		.bar_left {
			flex: 2;
		}
		.bar_right {
			flex: 5;
			display: flex;
			align-items: center;
			justify-content: center;
			.gongji {
				flex: 2;
				font-size: 24upx;
				color: #9f9f9f;
			}
			.heji {
				flex: 3;
				text {
					color: #dd7d01;
				}
			}
			.jiesuan {
				flex: 2;
				.jiesuan_btn {
					width: 90%;
					height: 70upx;
					border-radius: 35upx;
					background-image: linear-gradient(top, #bd9a74, #f6d2a0);
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 32upx;
					box-shadow: 0 10upx 30upx #cacaca;
				}
			}
		}
	}
}
.choose_transfer_box{
	width: 100%;
}
.textActive{
	background-color: rgb(0,122,255);
	font-weight: 500;
	color: white;
}
</style>
